# def text_create(name, msg):
#     desktop_path = '/Users/macOS/Desktop/demo/'
#     full_path = desktop_path + name + '.txt'
#     file = open(full_path, 'w')
#     file.write(msg)
#     file.close()
#     print('Done')
#
# def text_filter(word, censored_word = 'lame', changed_word = 'Awesome'):
#     return word.replace(censored_word, changed_word)
#
# def censored_text_create(name, msg):
#     clean_msg = text_filter(msg)
#     text_create(name,clean_msg)

# censored_text_create('Try', 'lame!lame!lame!')
# text_filter('Python is lame!')
# text_create('001', 'zml')

# 嵌套循环
# for i in range(1, 10):
#     for j in range(1,10):
#         print('{} X {}'.format(i, j, i*j))

# 在桌面上创建10个以数字命名的文本
# def test_text_create():
#     desktop_path = '/Users/macOS/Desktop/demo/'
#     for name in range(1,11):
#         with open(desktop_path + str(name) + '.txt', 'w')as text:
#             text.write(str(name))
#             text.close()
#
# test_text_create()

# 复利计算函数
# def invest(amount, rate, time):
#     print('amount:{}'.format(amount))
#     for t in range(1, time+1):
#         amount = amount * (1 + rate)
#         print('year {}: ${}'.format(t, amount))
# invest(100, .05, 8)

# 1~100以内的偶数
# def even_print():
#     for i in range(1, 101):
#         if i % 2 == 0 :
#             print(i)
# even_print()

# 随机验证码
import random
checkcode = ''
for i in range(4):
    print('i:', i)
    # 返回指定递增基数集合中的一个随机数
    current = random.randrange(0, 4)
    print('current:', current)
    if current != i:
        # 返回一随机数对应的字符
        temp = chr(random.randint(65, 90))
    else:
        temp = random.randint(0, 9)
    checkcode += str(temp)
print(checkcode)